<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://www.ccut.edu.cn/saturn" prefix="saturn"%>
<%@page import="edu.ccut.saturn.component.SaturnDebugThreadsManager"%>
<%@page import="java.util.*"%>
<%@page import="edu.ccut.saturn.component.IDebugThread"%>

<%@ include file="/jsp/include/header/meta.jsp"%>
<%@ include file="/jsp/include/header/stylesheettag.jsp"%>
<%@ include file="/jsp/include/header/javascript.jsp"%>

<%@page import="java.util.StringTokenizer"%>
<%@page import="edu.ccut.saturn.component.IDebugComponentInfo"%>
<%@page import="edu.ccut.saturn.component.impl.SaturnDebugLogMessage"%>
<%@page import="edu.ccut.saturn.component.IParameter"%>
<%@page import="edu.ccut.saturn.component.IParameterContext"%>
<%@page import="edu.ccut.saturn.component.IParameterInfo"%>
<html>
<head>
<title>Saturn Debug</title>
</head>
<script type="text/javascript">
	function open(type,j){
		var url = "value.jsp?type="+type+"&index="+j;
		window.showModalDialog(url,window, "dialogHeight: 400px; dialogWidth: 880px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");
	}
</script>
<body>
<%
	String name = request.getParameter("key");
	name= name.replace(SaturnDebugThreadsManager.SUB_STR, ",");
	StringTokenizer stringTokenizer = new StringTokenizer(name, ","); 
	
	String debugThreadName = stringTokenizer.nextToken();
	IDebugThread debugThread = SaturnDebugThreadsManager
			.getInstance().getOverDebugThread(debugThreadName);
			
	IDebugComponentInfo debugComponentInfo = debugThread.getDebugComponentInfo();
	
	while (stringTokenizer.hasMoreTokens()) {
		int index = Integer.parseInt(stringTokenizer.nextToken());
		debugComponentInfo = debugComponentInfo.getChildren().get(index);
	}
		
	request.setAttribute("component", debugComponentInfo);
%>

<saturn:formBeans name="nonull" title="Debug 组件明细" action="">
	<saturn:formBean type="label" name="name" label="名称"
		value="${component.name}" />
	<saturn:formBeanLine />

	<saturn:formBean type="label" name="name" label="组件标识"
		value="${component.nodeInfo.key}" />
	<saturn:formBeanLine />

	<saturn:formBean type="label" name="startTime" label="开始时间"
		value="${component.startTimeStr}" />
	<saturn:formBeanLine />

	<saturn:formBean type="label" name="endTime" label="结束时间"
		value="${component.endTimeStr}" />
	<saturn:formBeanLine />

	<saturn:formBean type="label" name="runTime" label="运行时间(秒)"
		value="${(component.endTime - component.startTime) / 1000}" />
	<saturn:formBeanLine />
</saturn:formBeans>

<%
	List parameterInfo = debugComponentInfo.getNodeInfo().getParameterInfos();
	
	if (parameterInfo != null) {
		request.setAttribute("parameterInfos", parameterInfo);
		
		IParameterContext beforeParameterContext = debugComponentInfo.getBeforeComponentParameterContext();
		
		if (beforeParameterContext != null) {
			List beforeParameters = beforeParameterContext.getParameters();
			session.setAttribute("debug_saturn_value_before", beforeParameters);
			session.setAttribute("debug_saturn_value_before_context", beforeParameterContext.getLogicContext());
			int i = 0;
%>

<saturn:formBeans name="before" title="执行前参数信息" action="">

	<table>
		<tr>
			<td>上下文信息</td>
			<td><a href="value.jsp?context=debug_saturn_value_before_context"
				target="_blank">显示内容</a></td>
		</tr>
	</table>

	<saturn:table id="beforeParameters" value="${parameterInfos}" item="var"
		isPagepilot="true" percount="5">
		<saturn:tableColumn title="名称" width="100">${var.name}</saturn:tableColumn>
		<saturn:tableColumn title="类型" width="100">${var.classType.simpleName}</saturn:tableColumn>
		<saturn:tableColumn title="范围">${debug_saturn_scope[var.scope]}</saturn:tableColumn>
		<saturn:tableColumn title="输入输出">${debug_saturn_in_out[var.passingType]}</saturn:tableColumn>
		<saturn:tableColumn title="key" width="200">${var.valueKey}</saturn:tableColumn>
		<saturn:tableColumn title="值">
			<%
			IParameter beforeParameter = (IParameter)beforeParameters.get(i);
			Object beforeValue = beforeParameter.getValue();
			if (beforeValue == null) {
				out.print("null");
			} else if (beforeValue instanceof String || beforeValue instanceof Number || beforeValue instanceof Boolean) {
				out.print(beforeValue.toString());
			} else {
			%>
			<a href="javascript:open('debug_saturn_value_before',<%=i%>)">查看內容</a>
			<%
			}
			++i;
			%>
		</saturn:tableColumn>

	</saturn:table>
</saturn:formBeans>
<% 		
		}
		
		IParameterContext afterParameterContext = debugComponentInfo.getAfterComponentParameterContext();
		
		if (afterParameterContext != null) {
			List afterParameters = afterParameterContext.getParameters();
			session.setAttribute("debug_saturn_value_after", afterParameters);
			session.setAttribute("debug_saturn_value_after_context", beforeParameterContext.getLogicContext());
			
			int j = 0;
 %>
<saturn:formBeans name="before" title="执行后参数信息" action="">

	<table>
		<tr>
			<td>上下文信息</td>
			<td><a href="value.jsp?context=debug_saturn_value_after_context"
				target="_blank">显示内容</a></td>
		</tr>
	</table>

	<saturn:table id="afterParameter" value="${parameterInfos}" item="var"
		isPagepilot="true" percount="5">

		<saturn:tableColumn title="名称" width="100">${var.name}</saturn:tableColumn>
		<saturn:tableColumn title="类型" width="100">${var.classType.simpleName}</saturn:tableColumn>
		<saturn:tableColumn title="范围">${debug_saturn_scope[var.scope]}</saturn:tableColumn>
		<saturn:tableColumn title="输入输出">${debug_saturn_in_out[var.passingType]}</saturn:tableColumn>
		<saturn:tableColumn title="key" width="200">${var.valueKey}</saturn:tableColumn>
		<saturn:tableColumn title="值">
			<%
			IParameter afterParameter = (IParameter)afterParameters.get(j);
			Object afterValue = afterParameter.getValue();
			if (afterValue == null) {
				out.print("null");
			
			} else if (afterValue instanceof String || 
					afterValue instanceof Number || 
					afterValue instanceof Boolean ) {
				out.print(afterValue.toString());
				
			} else {
			%>
			<a href="javascript:open('debug_saturn_value_after',<%=j%>)">查看內容</a>
			<%
			}
			++j;
			%>
		</saturn:tableColumn>
	</saturn:table>
</saturn:formBeans>
<%
		}
	} 
%>

<saturn:formBeans name="before" title="日志信息" action="">
	<saturn:table id="logtable" value="${component.logMessages}" item="var"
		isPagepilot="true" percount="20" isCursor="true">

		<saturn:tableColumn title="名称" width="100">${var.key}</saturn:tableColumn>
		<saturn:tableColumn title="级别" width="100">${var.level}</saturn:tableColumn>
		<saturn:tableColumn title="信息">${var.message}</saturn:tableColumn>
		<saturn:tableColumn title="异常">${var.exception}</saturn:tableColumn>
	</saturn:table>
</saturn:formBeans>
</body>
</html>